package com.hd.trans.ui.model

import android.os.CountDownTimer
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.hd.trans.network.bean.aiChat.AIAnswer

class AiChatViewModel: ViewModel() {
    val mLiveResult = MutableLiveData<AIAnswer>()
    val mLoading = MutableLiveData<String>()

    //AI思考倒计时器
    private var countDownTimer: CountDownTimer? = null
    private val list = mutableListOf("小助手正在思考中.", "小助手正在思考中..", "小助手正在思考中...")
    private var currentIndex = 0
    fun startCountDownTimer() {
        stopCountDownTimer()
        countDownTimer = object : CountDownTimer(5 * 60 * 1000, 300) {
            override fun onTick(millisUntilFinished: Long) {

                mLoading.postValue(list[currentIndex])
                currentIndex++
                if (currentIndex > 2) {
                    currentIndex = 0
                }
            }

            override fun onFinish() {

            }
        }
        countDownTimer?.start()
    }

    fun stopCountDownTimer() {
        currentIndex = 0
        countDownTimer?.cancel()
    }
}